package sort.sort;

import java.util.Arrays;
import java.util.List;

public abstract class Sort {
    protected Integer[] array;
    private int cmpCount = 0;
    private int swapCount = 0;
    public void sortArray(Integer[] array) {
        if (array == null || array.length < 2) {return;}
        this.array = array;
        sort();
    }
    protected abstract void sort();
    protected int cmp(int i1,int i2) {
        cmpCount++;
        return i1 - i2;
    }
    protected void swap(int i1,int i2) {
        swapCount++;
        int tmp = array[i1];
        array[i1] = array[i2];
        array[i2] = tmp;
    }
    public int getCmpCount() {
        return cmpCount;
    }

    public int getSwapCount() {
        return swapCount;
    }
    public void print() {
        List<Integer> integerList = Arrays.asList(array);
        System.out.println(integerList);
        System.out.println("比较次数：" + cmpCount);
        System.out.println("交换次数：" + swapCount);
    }
}
